﻿using System;
using System.Collections.Generic;
using System.Text;
using CC.Models;
using Dapper;

namespace CC.BLLs
{
    public class LikeBLL
    {
        public static bool Like(string outId, long memberId)
        {
            using (var conn = DatabaseHelper.Get())
            {
                return conn.Execute(@"INSERT INTO `comment_like` (`OutId`, `MemberId`, `CreateTime`) 
                                VALUES
                                  (@OutId, @MemberId, @CreateTime)", new { OutId = outId, MemberId = memberId, CreateTime = DateTime.Now }) > 0;
            }
        }

        public static bool Has(string outId, long memberId)
        {
            using (var conn = DatabaseHelper.Get())
            {
                return conn.ExecuteScalar<int>("select count(1) from comment_like where OutId=@OutId and MemberId=@MemberId", new { OutId = outId, MemberId = memberId }) > 0;
            }
        }

        public static List<string> MemberLike(List<string> outIds, long memberId)
        {
            using (var conn = DatabaseHelper.Get())
            {
                return conn.Query<string>("select  OutId from comment_like where OutId in @OutIds and MemberId=@MemberId", new { OutIds = outIds, MemberId = memberId }).AsList();
            }
        }

        public static bool UnLike(string outId, long memberId)
        {
            using (var conn = DatabaseHelper.Get())
            {
                return conn.Execute("delete from comment_like  where OutId=@OutId and MemberId=@MemberId", new { OutId = outId, MemberId = memberId }) > 0;
            }
        }
    }
}
